from flask_restful import Resource

from restful.api__.session import login_required_current_user_generate, uid_required_target_user_generate
from restful.model.query import QueryMultipleInstances
from restful.model.tables import Check, Like
from restful.response import ResponseSuccess


class UserAllPostsPublishedGetLikes(Resource):
    @login_required_current_user_generate
    @uid_required_target_user_generate
    def get(self, current_user,target_user):
        checks = QueryMultipleInstances(Check,{'uid':target_user.id,'checked':True,'passed':True})
        likes = 0
        for i in checks:
            likes += len(QueryMultipleInstances(Like,{'pid':i.pid}))
        return ResponseSuccess(data={
            'count':likes
        })